package _12_回溯;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class _78_子集 {

    public static void main(String[] args) {

        _78_子集 v = new _78_子集();

        int[] ins = new int[]{1, 2, 3};
        List<List<Integer>> subsets = v.subsets(ins);
        for (List<Integer> subset : subsets) {
            System.out.println(subset);
        }

    }

    private List<List<Integer>> results = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        dfs(nums, 0, new ArrayList<>());

        return results;
    }

    private void dfs(int[] nums, int i, List<Integer> tempStore) {

        results.add(new ArrayList<>(tempStore));

        for (int j = i; j < nums.length; j++) {
            tempStore.add(nums[j]);
            dfs(nums, j + 1, tempStore);
            // 回溯
            tempStore.remove(tempStore.size() - 1);
        }
    }

}
